package com.license.cso.test;

import java.awt.Point;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.TransformerException;

import org.junit.Test;
import org.w3c.dom.DOMException;
import org.xml.sax.SAXException;

import com.license.common.util.Constants;
import com.license.common.xmlparser.WriteExcel;
import com.license.logic.behaviorlog.WriteXML;
import com.license.logic.clonalselection.Antibody;
import com.license.logic.clonalselection.ClonalSelectionOptimization;

public class ClonalComparation {
	
	@Test
	public void testWriteExcel(){
		Map<Point, Long> test = new HashMap<Point, Long>();
		
		Point point1 = new Point(10, 10);
		Point point2 = new Point(20, 20);
		
		test.put(point1, Long.valueOf(500));
		test.put(point2, Long.valueOf(700));
		
		try {
//			WriteXML writeXML  = new WriteXML();
//			writeXML.saveTestLogs(test, Constants.XML_RESULTS_CSO);
			
			WriteExcel writeExcel = new WriteExcel();
			writeExcel.writeTestForCSO(test,  Constants.XML_RESULTS_CSO + Constants.EXCELL_EXTENSION);
		} catch (Exception e){
			
		}
		
	}
	
	@Test
	public void testClonalComparation () throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException, TransformerException, XMLStreamException {
		int antibodyNr = 10;
		int antibodyIt = 10;
		int betaValue = 1;
		int paretoOptimal = 2;
		int cloneNr = 30;
		
		WriteExcel writeExcel = new WriteExcel();
		
		Long startTime = System.currentTimeMillis();
		long endTime = System.currentTimeMillis();
		String path = Constants.EXTERN_FILE_PATH_UNCLASSIFIED + "employee13.xml";
		
		ClonalSelectionOptimization clonalSelectionOptimization = new ClonalSelectionOptimization(path, antibodyNr, antibodyIt, 
				paretoOptimal,Constants.DIET_NUMBER_GENERATED, betaValue, cloneNr);
		
		Map<Point, Long> test = new HashMap<Point, Long>();
		
//		for (int antN = 10 ; antN <= 100; antN +=10){
//			for (int antI = 10; antI <= 100; antI +=10){
//				Point point = new Point(antN, antI);
//				startTime = System.currentTimeMillis();
//				//
//				clonalSelectionOptimization.setAntibodyNumber(antN);
//				clonalSelectionOptimization.setBetaValue(betaValue);
//				clonalSelectionOptimization.setClonedAntibodyNr(cloneNr);
//				clonalSelectionOptimization.setCloneIteration(antI);
//				clonalSelectionOptimization.setParetoOptimalMethod(paretoOptimal);
//				
//				clonalSelectionOptimization.clonalSelectionOptimization();
//				endTime = System.currentTimeMillis();
//				test.put(point, endTime-startTime);
//			}
//		}
//		
//		writeExcel.writeTestForCSO(test, Constants.XML_RESULTS_CSO +"_pareto2_"+ Constants.EXCELL_EXTENSION);
		
			for (int antI = 10; antI <= 70; antI +=10){
				Point point = new Point(antI, 3);
				startTime = System.currentTimeMillis();
				//
				clonalSelectionOptimization.setAntibodyNumber(antI);
				clonalSelectionOptimization.setClonedAntibodyNr(antI);
				clonalSelectionOptimization.setCloneIteration(antI);
				
				clonalSelectionOptimization.clonalSelectionOptimization();
				endTime = System.currentTimeMillis();
				test.put(point, endTime-startTime);
			}
		
		writeExcel.writeTestForCSO(test, Constants.XML_RESULTS_CSO +"_cloneNumber_"+ Constants.EXCELL_EXTENSION);
		
//		for (int antN = 10 ; antN <= 70; antN +=10){
//			for (int antI = 1; antI <= 7; antI ++){
//				Point point = new Point(antN, antI);
//				startTime = System.currentTimeMillis();
//				//
//				clonalSelectionOptimization.setClonedAntibodyNr(cloneNr);
//				clonalSelectionOptimization.setAntibodyNumber(antN);
//				clonalSelectionOptimization.setBetaValue(antI);
//				clonalSelectionOptimization.setCloneIteration(antN);
//				
//				clonalSelectionOptimization.clonalSelectionOptimization();
//				endTime = System.currentTimeMillis();
//				test.put(point, endTime-startTime);
//			}
//		}
//		
//		writeExcel.writeTestForCSO(test, Constants.XML_RESULTS_CSO +"_betaValue_"+ Constants.EXCELL_EXTENSION);
		
//		for (Integer i : test.keySet()){
//			System.out.println("################# i #################");
//			for (Long l : test.get(i)){
//				System.out.println("L : " + l);
//			}
//			
//		}
		
		
		long duration = endTime - startTime;
		System.out.println("################################################################################################");
		System.out.println("timpul in milisec :"  + duration);
		System.out.println("################################################################################################");
	}
	
	@Test
	public void testClonalSelectionOptimization() 
			throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException, TransformerException, XMLStreamException {
		Long startTime = System.currentTimeMillis();
		String path = Constants.EXTERN_FILE_PATH_UNCLASSIFIED + "employee13.xml";
		System.out.println(new Date(startTime));
		ClonalSelectionOptimization clonalSelectionOptimization = new ClonalSelectionOptimization(path, Constants.CLONAL_ANTIBODY_NUMBER, Constants.CLONAL_ITERATION_NUMBER, 
				1,Constants.DIET_NUMBER_GENERATED, Constants.CLONAL_BETA_NUMBER, Constants.CLONAL_ANTIBODY_CLONED_NUMBER);
		
		List<Antibody> solutions = clonalSelectionOptimization.clonalSelectionOptimization();
		WriteXML writeXML = new WriteXML();
		writeXML.printAntibodyDiet(solutions, "employee19");
		
		System.out.println("###################3");
		System.out.println("difference:" + clonalSelectionOptimization.getDifferenceFromPreprocessing());
		System.out.println("###################3");
		
		System.out.println("solution : " + solutions);
		long endTime = System.currentTimeMillis();
		System.out.println(new Date (endTime));
		
		
	}
}
